#include <iostream>
#include <memory>
#include <string>
#include <grpcpp/grpcpp.h>
#include "demo.grpc.pb.h"

class GreeterServiceImpl final :public hello::Greeter::Service {
	virtual ::grpc::Status SayHello(::grpc::ServerContext* context,
		const ::hello::HelloRequest* request, ::hello::HelloReply* response) {
		std::string prefix("Server has received :");
		response->set_message(prefix + request->message());
		return grpc::Status::OK;
	}
};

void RunServer() {
	std::string server_address("0.0.0.0:40000");
	GreeterServiceImpl service;
	grpc::ServerBuilder builder;
	builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
	builder.RegisterService(&service);
	std::unique_ptr<grpc::Server> server(builder.BuildAndStart());
	std::cout << "Server listening on " << server_address << std::endl;
	server->Wait();
}

int main(int agec, char* argv[]) {
	RunServer();
	return 0;
}